//============================================================================
// Name        : myproject.cpp
// Author      : guanlei
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <string.h>

#include "func.h"
using namespace std;


int main(int argc, char* argv[]) {
	cout << "�������ļ�1��·��:" << endl;
	std::string file_one ="";// "d:\\common.php";
	strcpy(cmpy_file_name_1,file_one.c_str());
	cin >> file_one;
	cout << "�������ļ�2��·��:" << endl;
	std::string  file_two="";// "d:\\en_common.php";
	cin >> file_two;
	strcpy(cmpy_file_name_2,file_two.c_str());
	fstream* f = new fstream();
	fstream* f2 = new fstream();
	if (f == 0) {
		cout << "File open error";
	}


	f->open(file_one.c_str());
	if(!f->is_open())
	{
		cout<<"���ļ�������������!";
		return 1;
	}
	string* str_temp = new string();
	while (f->getline(temp_str, 1024) != 0) {
		str_temp->assign(temp_str);
		size_t index = str_temp->find("=");
		size_t start_index = str_temp->find("$");
		size_t over_index = str_temp->find("//");
		if (index == string::npos) {
			continue;
		}
		if(over_index != string::npos)
		{
			if(over_index<start_index)
			{
				continue;
			}
		}
		string file1_str((str_temp->substr(start_index,index)));
		file1_str.replace(file1_str.begin(),file1_str.end(),"\"","\'");
		file_one_str_vec.push_back(file1_str);
	}
	f->close();
	sort(file_one_str_vec.begin(), file_one_str_vec.end());

	f2->open(file_two.c_str());
	if(!f2->is_open())
		{
			cout<<"���ļ�������������!";
			return 1;
		}
	while (f2->getline(temp_str, 1024) != 0) {
		str_temp->assign(temp_str);
		size_t start_index = str_temp->find("$");
		size_t index = str_temp->find("=");
		size_t over_index = str_temp->find("//");
		if (index == string::npos) {
			continue;
		}
		if(over_index != string::npos)
		{
			if(over_index<start_index)
			{
				continue;
			}
		}
		string file2_str(str_temp->substr(start_index,index));
		file_two_str_vec.push_back(file2_str);
	}
	f2->close();
	sort(file_two_str_vec.begin(), file_two_str_vec.end());
	std::vector<string>::iterator itr = file_one_str_vec.begin();
	/*while (itr != file_one_str_vec.end()) {
		cout << *itr << endl;
		itr++;
	}*/
	cout << "�ļ�һ���ַ�һ����" << file_one_str_vec.size() << endl;
	cout << "�ļ������ַ�һ����" << file_two_str_vec.size() << endl;

	cout<<"�ļ�һ���У����ļ���û�е�����"<<endl;
	check_two_vec_diff(&file_one_str_vec, &file_two_str_vec);
	const char* file_name_1="file_one_to_file_two.log";
	log_sta_file(file_name_1);
	cout<<"�ļ������У����ļ�һû�е�����"<<endl;
	check_two_vec_diff(&file_two_str_vec, &file_one_str_vec);
	const char* file_name_2="file_two_to_file_one.log";
	log_sta_file(file_name_2);
	delete f;
	delete f2;
	delete str_temp;
	return 0;
}


